package exercise.day4;
import java.util.Scanner;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: TODO
 * @date 2022/10/28 2:05
 */

public class DD5_DecimalConversion {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNextInt()) {
            int m = in.nextInt();
            int n = in.nextInt();
            StringBuilder s = new StringBuilder();
            String table = "0123456789ABCDEF";
            //用来存储2-16进制中所有的可能
            boolean flag = false; //标记下有没有加负号
            if(m < 0){
                m = -m;
                flag = true;
                //本身是负数，我们改为正数了。标记下
            }
            if(m == 0){
                s.append('0');
            }
            while (m != 0) {
                s.append(table.charAt(m % n));
                m /= n;
            }
            if(flag){
                s.append('-');
            }
            s.reverse();
            System.out.println(s);
        }

    }
}
